import java.util.Scanner;
public class second {
    //遍历数组找出最大子数组
    public static int maxnums(int[] nums) {
        int num = nums[0];
        int maxnum = nums[0];
        for (int i = 1; i < nums.length; i++) {
            num = Math.max(nums[i], num + nums[i]);
            maxnum = Math.max(maxnum, num);
        }
        return maxnum;
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("输入数组个数: ");
        int n = scanner.nextInt();
        if (n <= 0) {
            return;
        }
        int[] nums = new int[n];
        System.out.println("输入数组:");
        for (int i = 0; i < n; i++) {
            nums[i] = scanner.nextInt();
        }
        int maxnum = maxnums(nums);
        System.out.println("最大子数组: " + maxnum);
    }
}
